package com.alex.dao;

import com.alex.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * mybatis 支持使用注解来配置mapper,也就是可以编写xml mapper 文件.
 * 但是注解方式受制于形式,因此只能编写简单的sql语句,功能有限.
 * 对于复杂的sql语句,仍然需要使用xml文件来编写.
 * xml和注解也可以同时使用.
 */
@Mapper
public interface UserMapperAnnotation {

    @Select("insert into user(username, password) VALUES (#{username}, #{password})")
    int addUser(@Param("user") User user);

    @Select("delete from user where id=#{id}")
    int deleteUser(@Param("id") int id);

    @Select("update user set username=#{username}, password=#{password} where id=#{id}")
    int updateUser(@Param("user") User user);

    @Select("select * from user where id = #{id}")
    User queryUser(@Param("id") int id);

    @Select("select * from user where id=#{id}")
    User getUser(@Param("id") int id);

    @Select("select * from user")
    List<User> getUsers();
}
